package cmcc.gz.cgt.bean;

import java.util.ArrayList;
import java.util.List;

import cmcc.gz.cgt.generator.CodeGenerator;
import cmcc.gz.cgt.generator.StringUtil;

/**
 * 表实体
 * @ClassName: TableBean 
 * @author AndrewWen
 * @date 2013-1-14 下午5:05:31
 */
public class TableBean {

	/**
	 * 数据库
	 */
	private String tableSchem;
	
	
	/**
	 * 表名
	 */
	private String tableName;
	/**
	 * 表注释
	 */
	private String tableComment;
	
	/**
	 * 列
	 */
	private List<ColumnBean> columnList=new ArrayList<ColumnBean>();
	
	
	/**
	 * 包名
	 */
	private String domainPackage;
	/**
	 * 包路径
	 */
	private String domainPath;
	/**
	 * 类名
	 */
	private String domainClassName;
	
	
	/**
	 * 获得第一个主键
	 * @Title: getFirstPrimaryKey 
	 * @return
	 */
	public ColumnBean getFirstPrimaryKey()
	{
		
		for(ColumnBean tempCul:this.getColumnList())
		{
			if(tempCul.isPrimary())
			{
				return tempCul;
			}
		}
		return null;
		
	}
	
	/**
	 * 获得类小写头名字
	 */
	public String getLowerDomainClassName()
	{
		return StringUtil.getClassLower(this.getDomainClassName());
	}
	
	/*************************get set *************************/
	
	
	public String getDomainPackage() {
		
		return domainPackage;
	}
	public void setDomainPackage(String domainPackage) {
		this.domainPackage = domainPackage;
	}
	
	public String getDomainPath() {

		if(this.domainPath==null||this.domainPath=="")
		{
			this.domainPath=this.getDomainPackage().replace(".", "/");
		}
		
		return domainPath;
	}
	public void setDomainPath(String domainPath) {
		this.domainPath = domainPath;
	}
	
	public String getDomainClassName() {
		
		//System.out.println(this.tableName.substring(this.tableName.indexOf("_")+1,this.tableName.length()));
		
		if(CodeGenerator.flag.equals("0"))
		{
			//直接输出
			if(this.domainClassName==null||this.domainClassName=="")
			{
				this.domainClassName=StringUtil.getClassUpper(StringUtil.getDomainColumnName(this.tableName));
			}
			
		}else if(CodeGenerator.flag.equals("1"))
		{
			
			//去掉数字模块
			if(this.domainClassName==null||this.domainClassName=="")
			{
				this.domainClassName=StringUtil.getClassUpper(StringUtil.getDomainColumnName(this.tableName.substring(this.tableName.indexOf("_")+1,this.tableName.length())));
			}
		}
		
		
		return domainClassName;
	}
	public void setDomainClassName(String domainClassName) {
		this.domainClassName = domainClassName;
	}
	

	public String getTableComment() {
		return tableComment;
	}
	public void setTableComment(String tableComment) {
		this.tableComment = tableComment;
	}
	public String getTableName() {
		return tableName;
	}
	public void setTableName(String tableName) {
		this.tableName = tableName;
	}
	public List<ColumnBean> getColumnList() {
		return columnList;
	}
	public void setColumnList(List<ColumnBean> columnList) {
		this.columnList = columnList;
	} 
	public String getTableSchem() {
		return tableSchem;
	}
	public void setTableSchem(String tableSchem) {
		this.tableSchem = tableSchem;
	}
}
